* GSS analysis for: 
* Unions, Class Identification and Policy Attitudes
* Date: 03/31/22


use GSS_SubClass_clean.dta, clear


*******************************************************************************
***** Policy attitudes analysis.
*******************************************************************************


* Rescale variables to 0, 1.
foreach v of varlist govineq govhlppoor govhlpmed govdomore pid7 polviews {
    qui summ `v'
    gen `v'01 = (`v' - r(min)) / (r(max) - r(min))
}


* Models.
* Also save effects for plotting.
foreach v of varlist govineq01 govhlppoor01 govhlpmed01 govdomore01 {
	reg `v' b2.subcls b2.objcls5 i.union i.female age age2 i.race pid701 polviews01 i.region4 i.year
	estimates store m_`v'2
	xsvmat, from(r(table)') rowname(parm) names(col) rowlab(var) frame(res_`v'2, replace)
	frame res_`v'2 : gen depvar = "`v'"
}

* Combine frames.
* Collect all frame names.
local frn2 "res_govdomore012 res_govhlpmed012 res_govhlppoor012 res_govineq012"

* New frame for append.
frame create scls_results2

foreach fname of local frn2 {
	frame `fname' {
		tempfile `fname'
		save ``fname'', replace
	}
	frame scls_results2 : append using ``fname''
}

* Recode some labels.
frame scls_results2 {
	replace var = "Subj. lower" if parm == "1.subcls"
	replace var = "Subj. working (ref.)" if parm == "2b.subcls"
	replace var = "Subj. middle" if parm == "3.subcls"
	replace var = "Subj. upper" if parm == "4.subcls"
	replace var = "Obj. lower" if parm == "1.objcls5"
	replace var = "Obj. working (ref.)" if parm == "2b.objcls5"
	replace var = "Obj. lower mid." if parm == "3.objcls5"
	replace var = "Obj. upper mid." if parm == "4.objcls5"
	replace var = "Obj. upper" if parm == "5.objcls5"
	replace var = "Union mem." if parm == "1.union"
	replace var = "Female" if parm == "1.female"
	replace var = "White (ref.)" if parm == "1b.race"
	replace var = "Black" if parm == "2.race"
	replace var = "Other" if parm == "3.race"
	replace var = "Party ID" if parm == "pid701"
	replace var = "Ideology" if parm == "polviews01"
	replace var = "Northeast (ref.)" if parm == "1b.region4"
	replace var = "Midwest" if parm == "2.region4"
	replace var = "South" if parm == "3.region4"
	replace var = "West" if parm == "4.region4"
	replace depvar = "Gov. reduce ineq." if depvar == "govineq01"
	replace depvar = "Gov. help poor" if depvar == "govhlppoor01"
	replace depvar = "Gov. help sick" if depvar == "govhlpmed01"
	replace depvar = "Gov. do more" if depvar == "govdomore01"
	drop if var == "" | parm == "age" | parm == "_cons"
	save scls_coef2.dta, replace
}

* Drop frames.
foreach fname of local frn2 {
	frame drop `fname'
}




* Matching.

capture drop cem_*

recode subcls (2 = 1) (3 = 0) (1 4 = .), gen(subcls_wc)

cem edu5 (#0) female (#0) age (25 35 45 55 65 75 85) white (#0) region4 (#0) year (1980.5 1984.5 1987.5 1989.5 1991.5 1993.5 1996.5 2000.5 2004.5 2008.5 2012.5) if subcls_wc!=. , treatment(subcls_wc) showbreaks 

* 
foreach v of varlist govineq01 govhlppoor01 govhlpmed01 govdomore01 {
	reg `v' subcls_wc b2.objcls5 i.union i.female age age2 i.race pid701 polviews01 i.region4 i.year [iweight=cem_weights]
	estimates store m_`v'_cem
}


